package com.example.controller;

import com.example.common.Result;
import com.example.entity.Stu;
import com.example.mapper.StuMapper;
import com.example.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/result")
public class StuController {

    @Autowired
    private StuService stuService;
    @Qualifier("stuMapper")
    @Autowired
    private StuMapper stuMapper;

    // 获取所有学生信息
    @GetMapping("/listStudent")
    public Result listStudent(Stu stu) {
        List<Stu> stus = stuService.selectAll(stu);
        return Result.success(stus);
    }

    @GetMapping("/userStudent")
    public Result findById(@RequestParam Long id) {
        List<Stu> stus = stuService.getById(id);
        return Result.success(stus);
    }

    //添加
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Stu stu) {
        stuService.addStudent(stu);
        return Result.success();
    }
//编辑
    @PutMapping("/updateStudent")
    public Result updateStudent(@RequestBody Stu stu) {
        stuService.updateById(stu);
        return Result.success();
    }
//删除
    @DeleteMapping("/deleteStudent/{id}")
    public Result deleteStudent(@PathVariable Long id) {
        stuService.deleteById(id);
        return Result.success();
    }

}
